package com.example.doer.reading;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by doer on 2017/7/10.
 */

public class MesListAdapter extends BaseAdapter {
    Context context;
    List<Message> list;
    int res;

    public MesListAdapter(Context c,List<Message> l,int r){
        this.context=c;
        this.list=l;
        this.res=r;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Message getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(res,null);

        ImageView imageView=(ImageView)view.findViewById(R.id.mes_list_image);
        TextView textView1=(TextView)view.findViewById(R.id.mes_list_title);
        TextView textView2=(TextView)view.findViewById(R.id.mes_list_content);
        TextView textView3=(TextView)view.findViewById(R.id.mes_list_info);

        Message m =getItem(position);

        imageView.setImageResource(m.getResID());
        textView1.setText(m.getTitle());
        textView2.setText(m.getContent());

        textView3.setText(m.getInfo());
        return view;
    }

}
